package com.ruoyi.camp.api;

import com.ruoyi.camp.domain.CProject;
import com.ruoyi.camp.service.ICProjectService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 项目Controller
 * 
 * @author ruoyi
 * @date 2024-12-02
 */
@RestController
@RequestMapping("/wechat/project")
public class WxCProjectController extends BaseController
{
    @Autowired
    private ICProjectService cProjectService;

    @GetMapping("/getInfoByCampId/{campid}")
    public AjaxResult getInfoByCampId(@PathVariable("campid") String campId) {
        if (campId == null) {
            return error("营地Id不能为空");
        }
        List<CProject> list = cProjectService.getInfoByCampId(campId);
        return success(list);
    }
    @GetMapping("/getInfoByProjectId/{projectid}")
    public AjaxResult getInfoByScenicId(@PathVariable("projectid") String projectId) {
        if (projectId == null) {
            return error("其他项目Id不能为空");
        }
        CProject wxProject = cProjectService.getInfo(projectId);
        return success(wxProject);
    }

    /**
     * 新增项目
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody CProject cProject){
        if (cProject == null) {
            return error("数据不能为空");
        }
        if (cProject.getCampid() == null) {
            return error("营地Id不能为空");
        }
        if (cProject.getProjectname() == null) {
            return error("其他项目名称不能为空");
        }
        if (cProject.getOriginalprice() == null) {
            return error("原价不能为空");
        }
        return toAjax(cProjectService.insertCProject(cProject));
    }
    /**
     * 修改项目
     */
    @PutMapping("/update")
    public AjaxResult update(@RequestBody  CProject cProject) {
        if (cProject == null) {
            return error("数据不能为空");
        }
        if (cProject.getProjectid() == null) {
            return error("营地其他项目Id不能为空");
        }
        if (cProject.getCampid() == null) {
            return error("营地Id不能为空");
        }
        if (cProject.getProjectname() == null) {
            return error("其他项目名称不能为空");
        }
        if (cProject.getOriginalprice() == null) {
            return error("原价不能为空");
        }
        return toAjax(cProjectService.updateCProject(cProject));
    }
    /**
     * 删除项目
     */
    @DeleteMapping("/delete/{projectid}")
    public AjaxResult delete(@PathVariable("projectid") String projectId){
        if (projectId == null) {
            return error("其他项目Id不能为空");
        }
        return toAjax(cProjectService.deleteCProjectByProjectid(projectId));
    }
}
